package so.wy.servicecenter.businessbed.web.hospital;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import so.wy.servicecenter.base.check.CommonWebCheck;
import so.wy.servicecenter.base.exception.WebException;
import so.wy.servicecenter.base.frame.baseopt.BaseOptService;
import so.wy.servicecenter.base.frame.baseopt.BaseOptWeb;
import so.wy.servicecenter.base.frame.web.webhand.WebExceptionHandler;
import so.wy.servicecenter.businessbed.service.hospital.HospitalBuildingService;
import so.wy.servicecenter.businessbed.service.hospital.dto.HospitalBuildingDTO;
import so.wy.servicecenter.businessbed.service.hospital.dto.HospitalBuildingTreeDTO;

import java.util.List;


@Service
@Scope("prototype")
public class HospitalBuildingWeb extends BaseOptWeb<HospitalBuildingDTO> {
    @Autowired
    private HospitalBuildingService hospitalBuildingService;

    @Override
    protected BaseOptService getOptService() {
        return hospitalBuildingService;
    }

    @Override
    public HospitalBuildingDTO addRecord(HospitalBuildingDTO query) throws WebException {
        CommonWebCheck.validateNotEmpty(query,"参数异常");
        CommonWebCheck.validateNotEmpty(query.getHospitalId(),"请选择医院");

        if (query.getParentId() == null){
            query.setParentId(0L);
        }

        return super.addRecord(query);
    }

    @WebExceptionHandler
    public List<HospitalBuildingTreeDTO> getHospitalTree(Long hospitalId){
        return hospitalBuildingService.getHospitalTree(hospitalId);
    }
}
